package de.dhbw.karlsruhe.picsim.model.commands.impl;

import de.dhbw.karlsruhe.picsim.model.actions.PicAction;
import de.dhbw.karlsruhe.picsim.model.commands.PicInstruction;
import de.dhbw.karlsruhe.picsim.model.cpu.PicInstructionFacade;
import de.dhbw.karlsruhe.picsim.model.memory.RegisterValue;
import de.dhbw.karlsruhe.picsim.model.memory.impl.RegisterValueImpl;
import de.dhbw.karlsruhe.picsim.util.Bits;
import de.dhbw.karlsruhe.picsim.util.impl.BitUtilities;
import de.dhbw.karlsruhe.picsim.util.impl.BitsMutableImpl;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: goesen
 * Date: May 3, 2010
 * Time: 3:53:01 PM
 */
public class RETFIE implements PicInstruction {

    @NotNull
    @Override
    public List<? extends PicAction> getActions(@NotNull final PicInstructionFacade pic) {
        final List<PicAction> list = new ArrayList<PicAction>();
        final Bits address = BitUtilities.asLeastSignificantBitFirst(0xb, 7);
        final RegisterValue value = pic.getFor7BitAddress(address).getData();
        final BitsMutableImpl bitsMutable = new BitsMutableImpl(value);
        bitsMutable.setBit(7, false);
        list.add(pic.getActionFactory().createWriteInFileAction(address, new RegisterValueImpl(bitsMutable)));
        list.add(pic.getActionFactory().popFromStackAction());

        return list;
    }
}
